package com.yanqu.xiuxian.crosssystem.manger.elementalbonds.pb;

import com.yanqu.xiuxian.config.elementalbonds.ElementalBondsConfigMgr;
import com.yanqu.xiuxian.config.elementalbonds.ElementalBondsParam;
import com.yanqu.xiuxian.config.elementalbonds.ElementalBondsScoreConfig;
import com.yanqu.xiuxian.config.elementalbonds.enums.ElementalBondsBlockEffectType;
import com.yanqu.xiuxian.config.elementalbonds.enums.ElementalBondsBombType;
import com.yanqu.xiuxian.config.elementalbonds.enums.ElementalBondsHonorMomentType;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.data.*;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity.*;

import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.param.ElementalBondsCardParam;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.param.ElementalBondsMoveParam;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.param.ElementalBondsSkillParam;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.result.ElementalBondsOperateResult;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.result.ElementalBondsOperateRoundResult;

import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.result.ElementalBondsOperateStageResult;
import com.yanqu.xiuxian.entity.redis.player.PlayerShowData;
import com.yanqu.xiuxian.pb.common.PlayerInfoPb;
import com.yanqu.xiuxian.pb.elementalbonds.ElementalBonds.*;
import com.yanqu.xiuxian.pb.player.Rank;
import com.yanqu.xiuxian.pb.player.WatchPlayer.PlayerBaseDataMsg;
import com.yanqu.xiuxian.redis.PlayerRedisMgr;
import com.yanqu.xiuxian.utils.TimeUtils;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

public class CrossElementalBondsPb {

    public static ElementalBondsOpponentMsg.Builder parseElementalBondsOpponentMsg(ElementalBondsMatchData elementalBondsMatchData) {
        ElementalBondsOpponentMsg.Builder elementalBondsOpponentMsgBuilder = ElementalBondsOpponentMsg.newBuilder();
        elementalBondsOpponentMsgBuilder.setScore(elementalBondsMatchData.getScore());
        elementalBondsOpponentMsgBuilder.setUserId(elementalBondsMatchData.isAi() ? 0 : elementalBondsMatchData.getPlayerId());
        if (!elementalBondsMatchData.isAi()) {
            PlayerShowData playerShowData = PlayerRedisMgr.getInstance().getPlayerShowInfo(elementalBondsMatchData.getPlayerId());
            if (playerShowData != null) {
                elementalBondsOpponentMsgBuilder.setPlayerInfo(PlayerInfoPb.buildPlayerBaseDataMsg(playerShowData));
            }
        } else {
            PlayerBaseDataMsg.Builder playerBaseDataMsg = PlayerBaseDataMsg.newBuilder();
            playerBaseDataMsg.setNickName(elementalBondsMatchData.getName());
            playerBaseDataMsg.setHeadIcon(elementalBondsMatchData.getHeadId());
            playerBaseDataMsg.setAppearanceId(elementalBondsMatchData.getBodyId());
            elementalBondsOpponentMsgBuilder.setPlayerInfo(playerBaseDataMsg);
        }

        elementalBondsOpponentMsgBuilder.setChannelId(elementalBondsMatchData.getChannelId());
        //elementalBondsOpponentMsgBuilder.setServerName(elementalBondsMatchData.isAi() ? "" : elementalBondsMatchData.getServerName());
        return elementalBondsOpponentMsgBuilder;
    }

    public static ElementalBondsRoomDataMsg.Builder parseElementalBondsRoomDataMsg(ElementalBondsRoomData elementalBondsRoomData, String selfKey) {
        boolean isPlayer1 = Objects.equals(elementalBondsRoomData.getPlayer1().getElementalBondsMatchData().getKey(), selfKey);
        int side = isPlayer1 ? 1 : 2;
        return parseElementalBondsRoomDataMsg(elementalBondsRoomData, side);
    }

    public static ElementalBondsRoomDataMsg.Builder parseElementalBondsRoomDataMsg(ElementalBondsRoomData elementalBondsRoomData, int side) {
        ElementalBondsPlayerData self = side == 1 ? elementalBondsRoomData.getPlayer1() : elementalBondsRoomData.getPlayer2();
        ElementalBondsPlayerData opponent = side == 1 ? elementalBondsRoomData.getPlayer2() : elementalBondsRoomData.getPlayer1();

        ElementalBondsRoomDataMsg.Builder elementalBondsRoomDataMsgBuilder = ElementalBondsRoomDataMsg.newBuilder();
        elementalBondsRoomDataMsgBuilder.setModeId(elementalBondsRoomData.getModeId());
        if (elementalBondsRoomData.getGameData() != null) {
            elementalBondsRoomDataMsgBuilder.setSceneId(elementalBondsRoomData.getGameData().getSceneId());
            elementalBondsRoomDataMsgBuilder.setBoard(parseElementalBondsBoardMsg(elementalBondsRoomData.getGameData()));
        }
        elementalBondsRoomDataMsgBuilder.setOpponent(parseElementalBondsOpponentMsg(opponent.getElementalBondsMatchData()));
        elementalBondsRoomDataMsgBuilder.setSelfData(parseElementalBondsUserGameDataMsg(side, self));
        elementalBondsRoomDataMsgBuilder.setOpponentData(parseElementalBondsUserGameDataMsg(side == 1 ? 2 : 1, opponent));
        elementalBondsRoomDataMsgBuilder.setRound(elementalBondsRoomData.getRound());
        elementalBondsRoomDataMsgBuilder.setExpireTime(elementalBondsRoomData.getExpireTime());
        elementalBondsRoomDataMsgBuilder.setTurnSide(elementalBondsRoomData.getTurnPlayer());
        elementalBondsRoomDataMsgBuilder.setShowNo(elementalBondsRoomData.getShowNo());
        elementalBondsRoomDataMsgBuilder.setRoomId(elementalBondsRoomData.getRoomId());
        elementalBondsRoomDataMsgBuilder.setIsGuide(elementalBondsRoomData.isGuide());
        return elementalBondsRoomDataMsgBuilder;
    }

    public static ElementalBondsBoardMsg.Builder parseElementalBondsBoardMsg(ElementalBondsGameData elementalBondsGameData) {
        ElementalBondsBoardMsg.Builder elementalBondsBoardMsgBuilder = ElementalBondsBoardMsg.newBuilder();
        for (List<ElementalBondsBlock> elementalBondsBlockList : elementalBondsGameData.getBlockList()) {
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                elementalBondsBoardMsgBuilder.addBlockList(parseElementalBondsBlockMsg(elementalBondsBlock));
            }
        }
        for (Map<Integer, ElementalBondsBlock> elementalBondsBlockMap : elementalBondsGameData.getFrameMap().values()) {
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockMap.values()) {
                elementalBondsBoardMsgBuilder.addBlockList(parseElementalBondsBlockMsg(elementalBondsBlock));
            }
        }
        return elementalBondsBoardMsgBuilder;
    }

    public static ElementalBondsUserGameDataMsg.Builder parseElementalBondsUserGameDataMsg(int side, ElementalBondsPlayerData elementalBondsPlayerData) {
        ElementalBondsUserGameDataMsg.Builder elementalBondsUserGameDataMsgBuilder = ElementalBondsUserGameDataMsg.newBuilder();
        elementalBondsUserGameDataMsgBuilder.setSide(side);
        elementalBondsUserGameDataMsgBuilder.setScore(elementalBondsPlayerData.getScore());
        elementalBondsUserGameDataMsgBuilder.setStep(elementalBondsPlayerData.getStep());

        ElementalBondsCardData elementalBondsCardData = elementalBondsPlayerData.getElementalBondsCardData();
        elementalBondsUserGameDataMsgBuilder.setCard(parseElementalBondsUserCardMsg(elementalBondsCardData));

        for (ElementalBondsSkillData elementalBondsSkillData : elementalBondsPlayerData.getElementalBondsSkillDataList()) {
            elementalBondsUserGameDataMsgBuilder.addSkill(parseElementalBondsUserSkillMsg(elementalBondsSkillData));
        }

        elementalBondsUserGameDataMsgBuilder.setUseBoardSkin(elementalBondsPlayerData.getBoardSkinId());
        elementalBondsUserGameDataMsgBuilder.setUseAnimation(elementalBondsPlayerData.getAnimationId());
        elementalBondsUserGameDataMsgBuilder.setUseEffect(elementalBondsPlayerData.getEffectId());
        return elementalBondsUserGameDataMsgBuilder;
    }

    public static ElementalBondsUserCardMsg.Builder parseElementalBondsUserCardMsg(ElementalBondsCardData elementalBondsCardData) {
        ElementalBondsUserCardMsg.Builder elementalBondsUserCardMsgBuilder = ElementalBondsUserCardMsg.newBuilder();
        elementalBondsUserCardMsgBuilder.setCardId(elementalBondsCardData.getCardId());
        elementalBondsUserCardMsgBuilder.setCardMp(elementalBondsCardData.getCardMp());
        elementalBondsUserCardMsgBuilder.setCardMaxMp(elementalBondsCardData.getCardMaxMp());
        return elementalBondsUserCardMsgBuilder;
    }

    public static ElementalBondsUserSkillMsg.Builder parseElementalBondsUserSkillMsg(ElementalBondsSkillData elementalBondsSkillData) {
        ElementalBondsUserSkillMsg.Builder elementalBondsUserSkillMsgBuilder = ElementalBondsUserSkillMsg.newBuilder();
        elementalBondsUserSkillMsgBuilder.setSkillId(elementalBondsSkillData.getSkillId());
        elementalBondsUserSkillMsgBuilder.setLeftTimes(elementalBondsSkillData.getTimes());
        return elementalBondsUserSkillMsgBuilder;
    }

    public static ElementalBondsBlockMsg.Builder parseElementalBondsBlockMsg(ElementalBondsBlock elementalBondsBlock) {
        ElementalBondsBlockMsg.Builder elementalBondsBlockMsgBuilder = ElementalBondsBlockMsg.newBuilder();
        elementalBondsBlockMsgBuilder.setX(elementalBondsBlock.getX());
        elementalBondsBlockMsgBuilder.setY(elementalBondsBlock.getY());
        elementalBondsBlockMsgBuilder.setType(elementalBondsBlock.getElementalBondsBlockType().getType());
        elementalBondsBlockMsgBuilder.setColor(elementalBondsBlock.getColor());
        elementalBondsBlockMsgBuilder.setDirection(elementalBondsBlock.getElementalBondsDirectionType().getType());
        for (ElementalBondsBlockEffect elementalBondsBlockEffect : elementalBondsBlock.getElementalBondsBlockEffectList()) {
            if (elementalBondsBlockEffect.getEffectType().getValue() <= ElementalBondsBlockEffectType.SERVER_BEGIN_VALUE) {
                elementalBondsBlockMsgBuilder.addEffect(parseElementalBondsBlockEffectMsg(elementalBondsBlockEffect));
            }
        }
        elementalBondsBlockMsgBuilder.setScore(elementalBondsBlock.getScore());
        elementalBondsBlockMsgBuilder.setSp(elementalBondsBlock.getSp());
        return elementalBondsBlockMsgBuilder;
    }

    public static ElementalBondsBlockEffectMsg.Builder parseElementalBondsBlockEffectMsg(ElementalBondsBlockEffect elementalBondsBlockEffect) {
        ElementalBondsBlockEffectMsg.Builder elementalBondsBlockEffectMsgBuilder = ElementalBondsBlockEffectMsg.newBuilder();
        elementalBondsBlockEffectMsgBuilder.setEffectType(elementalBondsBlockEffect.getEffectType().getValue());
        elementalBondsBlockEffectMsgBuilder.setEffectArg(elementalBondsBlockEffect.getEffectValue());
        return elementalBondsBlockEffectMsgBuilder;
    }

    public static ElementalBondsGameOverMsg.Builder parseElementalBondsGameOverMsg(ElementalBondsRoomData elementalBondsRoomData, String selfKey) {
        boolean isPlayer1 = Objects.equals(elementalBondsRoomData.getPlayer1().getElementalBondsMatchData().getKey(), selfKey);
        int side = isPlayer1 ? 1 : 2;
        ElementalBondsPlayerData selfElementalBondsPlayerData = isPlayer1 ? elementalBondsRoomData.getPlayer1() : elementalBondsRoomData.getPlayer2();
        ElementalBondsMatchData selfElementalBondsMatchData = selfElementalBondsPlayerData.getElementalBondsMatchData();
        ElementalBondsPlayerData opponentElementalBondsPlayerData = isPlayer1 ? elementalBondsRoomData.getPlayer2() : elementalBondsRoomData.getPlayer1();
        ElementalBondsMatchData opponentElementalBondsMatchData = opponentElementalBondsPlayerData.getElementalBondsMatchData();

        ElementalBondsGameOverMsg.Builder elementalBondsGameOverMsgBuilder = ElementalBondsGameOverMsg.newBuilder();
        elementalBondsGameOverMsgBuilder.setRoomData(parseElementalBondsRoomDataMsg(elementalBondsRoomData, selfKey));
        elementalBondsGameOverMsgBuilder.setWin(elementalBondsRoomData.getWinPlayer() == side);
        elementalBondsGameOverMsgBuilder.setEndType(elementalBondsRoomData.getWinType());
        elementalBondsGameOverMsgBuilder.setCostTime(TimeUtils.currentTimeMillis() - elementalBondsRoomData.getBeginTime());
        ElementalBondsScoreConfig elementalBondsScoreConfig = ElementalBondsConfigMgr.getInstance().getScoreConfig(selfElementalBondsMatchData.getScore(), opponentElementalBondsMatchData.isNovice());
        elementalBondsGameOverMsgBuilder.setScoreDiff(selfElementalBondsMatchData.getScore() - opponentElementalBondsMatchData.getScore());
        int selfCardQuality = ElementalBondsConfigMgr.getInstance().getCardQuality(selfElementalBondsMatchData.getCardId());
        int opponentCardQuality = ElementalBondsConfigMgr.getInstance().getCardQuality(opponentElementalBondsMatchData.getCardId());
        if (selfCardQuality < opponentCardQuality) {
            elementalBondsGameOverMsgBuilder.setOpponentCardDiff(opponentCardQuality - selfCardQuality);
        }


        for (Map.Entry<ElementalBondsHonorMomentType, Long> achieveStatisticalEntry : selfElementalBondsPlayerData.getAchieveStatisticalMap().entrySet()) {
            if (achieveStatisticalEntry.getValue() > 0L) {
                elementalBondsGameOverMsgBuilder.addHonorMoment(parseElementalBondsHonorMomentMsg(achieveStatisticalEntry.getKey(), achieveStatisticalEntry.getValue()));
            }
        }
        int battleResult;
        int funHun = 1;
        int limitTaskItem = 0;
        if (elementalBondsRoomData.getWinPlayer() == 3) {
            // 平局
            battleResult = 3;
        } else {
            if (elementalBondsRoomData.getWinPlayer() == side) {
                // 胜利
                battleResult = 1;
                funHun = 2;
                if (selfElementalBondsPlayerData.getScore() != 0 && opponentElementalBondsPlayerData.getScore() != 0) {
                    long rate = selfElementalBondsPlayerData.getScore() / opponentElementalBondsPlayerData.getScore() * 1000;
                    if (elementalBondsScoreConfig != null && rate >= elementalBondsScoreConfig.getScoreRate()) {
                        funHun = 3;
                    }
                }


            } else {
                // 败
                battleResult = 2;
            }
            limitTaskItem = ElementalBondsParam.getInstance().limitTaskItemNum(funHun);
        }
        elementalBondsGameOverMsgBuilder.setBattleResult(battleResult);
        elementalBondsGameOverMsgBuilder.setModeId(elementalBondsRoomData.getModeId());

        elementalBondsGameOverMsgBuilder.setFuhun(funHun);
        elementalBondsGameOverMsgBuilder.setLimitTimeItem(limitTaskItem);
        return elementalBondsGameOverMsgBuilder;
    }

    public static ElementalBondsOperateResultMsg.Builder parseElementalBondsOperateResultMsg(ElementalBondsOperateResult elementalBondsOperateResult,
                                                                                             ElementalBondsRoomData elementalBondsRoomData, String receiveUserKey) {
        ElementalBondsOperateResultMsg.Builder elementalBondsOperateResultMsgBuilder = ElementalBondsOperateResultMsg.newBuilder();
        elementalBondsOperateResultMsgBuilder.setSide(elementalBondsOperateResult.getTurn());
        elementalBondsOperateResultMsgBuilder.setSkillId(elementalBondsOperateResult.getSkillId());
        for (ElementalBondsOperateShow elementalBondsOperateShow : elementalBondsOperateResult.getElementalBondsOperateShowList()) {
            elementalBondsOperateResultMsgBuilder.addShow(parseElementalBondsShowMsg(elementalBondsOperateShow));
        }
        elementalBondsOperateResultMsgBuilder.setGameData(parseElementalBondsRoomDataMsg(elementalBondsRoomData, receiveUserKey));
        return elementalBondsOperateResultMsgBuilder;
    }

    public static ElementalBondsShowMsg.Builder parseElementalBondsShowMsg(ElementalBondsOperateShow elementalBondsOperateShow) {
        ElementalBondsShowMsg.Builder elementalBondsShowMsgBuilder = ElementalBondsShowMsg.newBuilder();
        for (ElementalBondsOperateEffect elementalBondsOperateEffect : elementalBondsOperateShow.getElementalBondsOperateEffectList()) {
            elementalBondsShowMsgBuilder.addEffects(parseElementalBondsEffectMsg(elementalBondsOperateEffect));
        }
        for (ElementalBondsOperateRoundResult elementalBondsOperateRoundResult : elementalBondsOperateShow.getElementalBondsOperateRoundResultList()) {
            elementalBondsShowMsgBuilder.addRoundResult(parseElementalBondsRoundResultMsg(elementalBondsOperateRoundResult));
        }
        return elementalBondsShowMsgBuilder;
    }

    public static ElementalBondsEffectMsg.Builder parseElementalBondsEffectMsg(ElementalBondsOperateEffect elementalBondsOperateEffect) {
        ElementalBondsEffectMsg.Builder elementalBondsEffectMsgBuilder = ElementalBondsEffectMsg.newBuilder();
        elementalBondsEffectMsgBuilder.setEffectType(elementalBondsOperateEffect.getEffectType());
        for (ElementalBondsBlock elementalBondsBlock : elementalBondsOperateEffect.getBlockList()) {
            elementalBondsEffectMsgBuilder.addBlockList(parseElementalBondsBlockMsg(elementalBondsBlock));
        }
        elementalBondsEffectMsgBuilder.setParam(elementalBondsOperateEffect.getParam());
        return elementalBondsEffectMsgBuilder;
    }

    public static ElementalBondsRoundResultMsg.Builder parseElementalBondsRoundResultMsg(ElementalBondsOperateRoundResult elementalBondsOperateRoundResult) {
        ElementalBondsRoundResultMsg.Builder elementalBondsRoundResultMsgBuilder = ElementalBondsRoundResultMsg.newBuilder();
        elementalBondsRoundResultMsgBuilder.setType(elementalBondsOperateRoundResult.isRearrange() ? 2 : 1);
        for (ElementalBondsOperateStageResult elementalBondsOperateStageResult : elementalBondsOperateRoundResult.getStageResultList()) {
            elementalBondsRoundResultMsgBuilder.addStageResult(parseElementalBondsStageResultMsg(elementalBondsOperateStageResult));
        }
        for (ElementalBondsBlock elementalBondsBlock : elementalBondsOperateRoundResult.getNewBombList()) {
            elementalBondsRoundResultMsgBuilder.addCreateBomb(parseElementalBondsBlockMsg(elementalBondsBlock));
        }
        elementalBondsRoundResultMsgBuilder.setBoard(parseElementalBondsBoardMsg(elementalBondsOperateRoundResult.getElementalBondsGameData()));
        return elementalBondsRoundResultMsgBuilder;
    }

    public static ElementalBondsStageResultMsg.Builder parseElementalBondsStageResultMsg(ElementalBondsOperateStageResult elementalBondsOperateStageResult) {
        ElementalBondsStageResultMsg.Builder elementalBondsStageResultMsgBuilder = ElementalBondsStageResultMsg.newBuilder();
        for (ElementalBondsBlock elementalBondsBlock : elementalBondsOperateStageResult.getEliminateBlockList()) {
            elementalBondsStageResultMsgBuilder.addBlockList(parseElementalBondsBlockMsg(elementalBondsBlock));
        }
        for (ElementalBondsBomb elementalBondsBomb : elementalBondsOperateStageResult.getBombList()) {
            if (elementalBondsBomb.getElementalBondsBombType() != ElementalBondsBombType.EMPTY) {
                elementalBondsStageResultMsgBuilder.addBoomList(parseElementalBondsBoomMsg(elementalBondsBomb));
            }
        }
        for (ElementalBondsBlock elementalBondsBlock : elementalBondsOperateStageResult.getAddStepBlockList()) {
            elementalBondsStageResultMsgBuilder.addBlockList2(parseElementalBondsBlockMsg(elementalBondsBlock));
        }
        return elementalBondsStageResultMsgBuilder;
    }

    public static ElementalBondsBoomMsg.Builder parseElementalBondsBoomMsg(ElementalBondsBomb elementalBondsBomb) {
        ElementalBondsBoomMsg.Builder elementalBondsBoomMsgBuilder = ElementalBondsBoomMsg.newBuilder();
        elementalBondsBoomMsgBuilder.setX(elementalBondsBomb.getX());
        elementalBondsBoomMsgBuilder.setY(elementalBondsBomb.getY());
        elementalBondsBoomMsgBuilder.setType(elementalBondsBomb.getElementalBondsBombType().getType());
        for (ElementalBondsBlock elementalBondsBlock : elementalBondsBomb.getElementalBondsBlockList()) {
            elementalBondsBoomMsgBuilder.addBlockList(parseElementalBondsBlockMsg(elementalBondsBlock));
        }
        return elementalBondsBoomMsgBuilder;
    }


    public static ElementalBondsFriendRoomInfoMsg.Builder parseElementalBondsFriendRoomInfoMsg(ElementalBondsRoomData roomData, boolean isPlayer1) {
        ElementalBondsPlayerData player1 = roomData.getPlayer1();
        ElementalBondsPlayerData player2 = roomData.getPlayer2();
        ElementalBondsPlayerData opponent = isPlayer1 ? player2 : player1;

        ElementalBondsFriendRoomInfoMsg.Builder builder = ElementalBondsFriendRoomInfoMsg.newBuilder();
        builder.setRoomId(String.valueOf(roomData.getRoomId()));
        if (opponent != null) {
            builder.setFriend(parseElementalBondsOpponentMsg(opponent.getElementalBondsMatchData()));
        }
        builder.setSceneId(roomData.getGameData() != null ? roomData.getGameData().getSceneId() : roomData.getAppointSceneId());
        builder.setStepOut(player1.getStepOutTime() > 0);

        builder.setMasterUserId(player1.getElementalBondsMatchData().getPlayerId());
        builder.setCardId1(player1.getElementalBondsMatchData().getCardId());
        if (player2 != null) {
            builder.setCardId2(player2.getElementalBondsMatchData().getCardId());
            builder.setReady(player2.isReady());
        } else {
            builder.setReady(false);
        }

        builder.addAllSkillId1(player1.getElementalBondsMatchData().getSkills());
        if (player2 != null) {
            builder.addAllSkillId2(player2.getElementalBondsMatchData().getSkills());
        }
        Set<Integer> cardPool = new HashSet<>();
        for (List<Integer> value : roomData.getCardPool().values()) {
            cardPool.addAll(value);
        }
        builder.addAllCardPool(cardPool);
        Set<Integer> skillPool = new HashSet<>();
        for (List<Integer> value : roomData.getSkillPool().values()) {
            skillPool.addAll(value);
        }
        builder.addAllSkillPool(skillPool);

        return builder;
    }

    public static ElementalBondsMoveParam parseElementalBondsMoveParam(ElementalBondsOperateReqMsg elementalBondsOperateReqMsg) {
        return new ElementalBondsMoveParam(elementalBondsOperateReqMsg.getFromX(), elementalBondsOperateReqMsg.getFromY(), elementalBondsOperateReqMsg.getToX(), elementalBondsOperateReqMsg.getToY());
    }

    public static ElementalBondsSkillParam parseElementalBondsUseSkillParam(ElementalBondsUseSkillMsg elementalBondsUseSkillMsg) {
        return new ElementalBondsSkillParam(elementalBondsUseSkillMsg.getId(), elementalBondsUseSkillMsg.getX(), elementalBondsUseSkillMsg.getY(), elementalBondsUseSkillMsg.getToX(), elementalBondsUseSkillMsg.getToY());
    }

    public static ElementalBondsCardParam parseElementalBondsUseCardParam(ElementalBondsUseSkillMsg elementalBondsUseSkillMsg) {
        return new ElementalBondsCardParam(elementalBondsUseSkillMsg.getId(), elementalBondsUseSkillMsg.getX(), elementalBondsUseSkillMsg.getY(), elementalBondsUseSkillMsg.getToX(), elementalBondsUseSkillMsg.getToY());
    }

    public static ElementalBondsHonorMomentMsg.Builder parseElementalBondsHonorMomentMsg(ElementalBondsHonorMomentType elementalBondsHonorMomentType, long statisticalValue) {
        ElementalBondsHonorMomentMsg.Builder elementalBondsHonorMomentMsgBuilder = ElementalBondsHonorMomentMsg.newBuilder();
        elementalBondsHonorMomentMsgBuilder.setHonorMomentType(elementalBondsHonorMomentType.getType());
        elementalBondsHonorMomentMsgBuilder.setValue(statisticalValue);
        return elementalBondsHonorMomentMsgBuilder;
    }

    public static void buildPoolData(ElementalBondsRoomData roomData, ElementalBondsFriendSyncRoomRespMsg.Builder builder) {
        Set<Integer> cardPool = new HashSet<>();
        for (List<Integer> value : roomData.getCardPool().values()) {
            cardPool.addAll(value);
        }
        builder.addAllCardPool(cardPool);
        Set<Integer> skillPool = new HashSet<>();
        for (List<Integer> value : roomData.getSkillPool().values()) {
            skillPool.addAll(value);
        }
        builder.addAllSkillPool(skillPool);
    }

    public static void getRankBuilder(List<ElementalBondsRankData> playerRankList, Rank.RankMsgList.Builder rankMsgList) {
        int rankNum = 0;
        for (ElementalBondsRankData bondsRankData : playerRankList) {
            long rankDataPlayerId = bondsRankData.getPlayerId();
            PlayerShowData playerShowData = PlayerRedisMgr.getInstance().getPlayerShowInfo(rankDataPlayerId);
            if (playerShowData == null) continue;
            Rank.RankTempMsg.Builder tmpMsg = Rank.RankTempMsg.newBuilder();
            tmpMsg.setPlayerCharacterImageMsg(PlayerInfoPb.builderPlayerCharacterImageMsg(playerShowData));
            tmpMsg.setValue(String.valueOf(bondsRankData.getScore()));
            rankMsgList.addRankTemp(tmpMsg);
            rankNum++;
            if (rankNum >= ElementalBondsParam.getInstance().getRankNum()) {
                break;
            }
        }
    }

}
